
// 保留号码
export const RetentionPhone = [
  "10086", "10010",
];
// 城
// 参考：https://ditu.so.com/zt/areacode.html
export const PhoneAreaCodes = [
  {code:"010", city:"北京"}, {code:"020", city:"广州"}, {code:"021", city:"上海"}, {code:"022", city:"天津"}, {code:"023", city:"重庆"},
  {code:"024", city:"沈阳"}, {code:"025", city:"南京"}, {code:"027", city:"武汉"}, {code:"028", city:"成都"}, {code:"029", city:"西安"},
  {code:"0371", city:"郑州"}, {code:"0411", city:"大连"}, {code:"0512", city:"苏州"}, {code:"0532", city:"青岛"}, {code:"0571", city:"杭州"},
  // 河北
  {code:"0310", city:"河北 邯郸"}, {code:"0311", city:"河北 石家庄"}, {code:"0312", city:"河北 保定"}, {code:"0313", city:"河北 张家口"}, {code:"0314", city:"河北 承德"},
  {code:"0315", city:"河北 唐山"}, {code:"0316", city:"河北 廊坊"}, {code:"0317", city:"河北 沧州"}, {code:"0318", city:"河北 衡水"}, {code:"0319", city:"河北 邢台"},
  {code:"0335", city:"河北 秦皇岛"},
  // 山西省
  {code:"0349", city:"山西 朔州"}, {code:"0350", city:"山西 忻州"}, {code:"0351", city:"山西 太原"}, {code:"0352", city:"山西 大同"}, {code:"0353", city:"山西 阳泉"},
  {code:"0354", city:"山西 晋中"}, {code:"0355", city:"山西 长治"}, {code:"0356", city:"山西 晋城"}, {code:"0357", city:"山西 临汾"}, {code:"0358", city:"山西 吕梁"},
  {code:"0359", city:"山西 运城"},
  // 内蒙古自治区
  {code:"0470", city:"内蒙古 呼伦贝尔"}, {code:"0471", city:"内蒙古 呼和浩特"}, {code:"0472", city:"内蒙古 包头"}, {code:"0473", city:"内蒙古 乌海"}, {code:"0474", city:"内蒙古 乌兰察布"},
  {code:"0475", city:"内蒙古 通辽"}, {code:"0476", city:"内蒙古 赤峰"}, {code:"0477", city:"内蒙古 鄂尔多斯"}, {code:"0478", city:"内蒙古 巴彦淖尔"}, {code:"0479", city:"内蒙古 锡林郭勒"},
  {code:"0482", city:"内蒙古 兴安盟"}, {code:"0483", city:"内蒙古 阿拉善"},
  // 湖北省
  {code:"027", city:"湖北 武汉"}, {code:"0710", city:"湖北 襄阳"}, {code:"0711", city:"湖北 鄂州"}, {code:"0712", city:"湖北 孝感"}, {code:"0713", city:"湖北 黄冈"},
  {code:"0714", city:"湖北 黄石"}, {code:"0715", city:"湖北 咸宁"}, {code:"0716", city:"湖北 荆州"}, {code:"0717", city:"湖北 宜昌"}, {code:"0718", city:"湖北 恩施"},
  {code:"0719", city:"湖北 十堰/农架林区"}, {code:"0722", city:"湖北 随州"}, {code:"0724", city:"湖北 荆门武汉"}, {code:"0728", city:"湖北 仙桃/潜江/天门"},
  // 辽宁省
  {code:"024", city:"辽宁 沈阳"}, {code:"0410", city:"辽宁 铁岭"}, {code:"0411", city:"辽宁 大连"}, {code:"0412", city:"辽宁 鞍山"}, {code:"0413", city:"辽宁 抚顺"},
  {code:"0414", city:"辽宁 本溪"}, {code:"0415", city:"辽宁 丹东"}, {code:"0416", city:"辽宁 锦州"}, {code:"0417", city:"辽宁 营口"}, {code:"0418", city:"辽宁 阜新"},
  {code:"0419", city:"辽宁 辽阳"}, {code:"0421", city:"辽宁 朝阳"}, {code:"0427", city:"辽宁 盘锦"}, {code:"0429", city:"辽宁 葫芦岛"},
  // 海南省
  {code:"0898", city:"海南"},
  // 吉林
  {code:"0423", city:"吉林 吉林"},	{code:"0431", city:"吉林 长春"},	{code:"0433", city:"吉林 延边"},	{code:"0434", city:"吉林 四平"},	{code:"0435", city:"吉林 通化"},
  {code:"0436", city:"吉林 白城"},	{code:"0437", city:"吉林 辽源"},	{code:"0438", city:"吉林 松原"},	{code:"0439", city:"吉林 白山"},
  // 黑龙江
  {code:"0451", city:"黑龙江 哈尔滨"},	{code:"0452", city:"黑龙江 齐齐哈尔"},	{code:"0453", city:"黑龙江 牡丹江"},	{code:"0454", city:"黑龙江 佳木斯"},	{code:"0455", city:"黑龙江 绥化"},
  {code:"0456", city:"黑龙江 黑河"},	{code:"0457", city:"黑龙江 大兴安岭"},	{code:"0458", city:"黑龙江 伊春"},	{code:"0459", city:"黑龙江 大庆"},	{code:"0464", city:"黑龙江 七台河"},
  {code:"0467", city:"黑龙江 鸡西"},	{code:"0468", city:"黑龙江 鹤岗"},	{code:"0469", city:"黑龙江 双鸭山"},
  // 江苏
  {code:"025", city:"江苏 南京"},	{code:"0510", city:"江苏 无锡"},	{code:"0511", city:"江苏 镇江"},	{code:"0512", city:"江苏 苏州"},	{code:"0513", city:"江苏 南通"},
  {code:"0514", city:"江苏 扬州"},	{code:"0515", city:"江苏 盐城"},	{code:"0516", city:"江苏 徐州"},	{code:"0517", city:"江苏 淮安"},	{code:"0518", city:"江苏 连云港"},
  {code:"0519", city:"江苏 常州"},	{code:"0523", city:"江苏 泰州"},	{code:"0527", city:"江苏 宿迁"},
  // 浙江
  {code:"0570", city:"浙江 衢州"},	{code:"0571", city:"浙江 杭州"},	{code:"0572", city:"浙江 湖州"},	{code:"0573", city:"浙江 嘉兴"},	{code:"0574", city:"浙江 宁波"},
  {code:"0575", city:"浙江 绍兴"},	{code:"0576", city:"浙江 台州"},	{code:"0577", city:"浙江 温州"},	{code:"0578", city:"浙江 丽水"},	{code:"0579", city:"浙江 金华"},
  {code:"0580", city:"浙江 舟山"},
  // 安徽
  {code:"0550", city:"安徽 滁州"},	{code:"0551", city:"安徽 合肥"},	{code:"0552", city:"安徽 蚌埠"},	{code:"0553", city:"安徽 芜湖"},	{code:"0554", city:"安徽 淮南"},
  {code:"0555", city:"安徽 马鞍山"},	{code:"0556", city:"安徽 安庆"},	{code:"0557", city:"安徽 宿州"},	{code:"0558", city:"安徽 阜阳/亳州"},
  {code:"0559", city:"安徽 黄山"},	{code:"0561", city:"安徽 淮北"},	{code:"0562", city:"安徽 铜陵"},	{code:"0563", city:"安徽 宣城"},	{code:"0564", city:"安徽 六安"},
  {code:"0566", city:"安徽 池州"},
  // 福建
  {code:"0591", city:"福建 福州"},	{code:"0592", city:"福建 厦门"},	{code:"0593", city:"福建 宁德"},	{code:"0594", city:"福建 莆田"},	{code:"0595", city:"福建 泉州"},
  {code:"0596", city:"福建 漳州"},	{code:"0597", city:"福建 龙岩"},	{code:"0598", city:"福建 三明"},	{code:"0599", city:"福建 南平"},
  // 江西
  {code:"0701", city:"江西 鹰潭"},	{code:"0790", city:"江西 新余"},	{code:"0791", city:"江西 南昌"},	{code:"0792", city:"江西 九江"},	{code:"0793", city:"江西 上饶"},
  {code:"0794", city:"江西 抚州"},	{code:"0795", city:"江西 宜春"},	{code:"0796", city:"江西 吉安"},	{code:"0797", city:"江西 赣州"},	{code:"0798", city:"江西 景德镇"},
  {code:"0799", city:"江西 萍乡"},
  // 山东
  {code:"0530", city:"山东 菏泽"},	{code:"0531", city:"山东 济南"},	{code:"0532", city:"山东 青岛"},	{code:"0533", city:"山东 淄博"},	{code:"0534", city:"山东 德州"},
  {code:"0535", city:"山东 烟台"},	{code:"0536", city:"山东 潍坊"},	{code:"0537", city:"山东 济宁"},	{code:"0538", city:"山东 泰安"},	{code:"0539", city:"山东 临沂"},
  {code:"0543", city:"山东 滨州"},	{code:"0546", city:"山东 东营"},	{code:"0631", city:"山东 威海"},	{code:"0632", city:"山东 枣庄"},	{code:"0633", city:"山东 日照"},
  {code:"0635", city:"山东 聊城"},
  // 河南
  {code:"0370", city:"河南 商丘"},	{code:"0371", city:"河南 郑州"},	{code:"0372", city:"河南 安阳"},	{code:"0373", city:"河南 新乡"},	{code:"0374", city:"河南 许昌"},
  {code:"0375", city:"河南 平顶山"},	{code:"0376", city:"河南 信阳"},	{code:"0377", city:"河南 南阳"},	{code:"0378", city:"河南 开封"},	{code:"0379", city:"河南 洛阳"},
  {code:"0391", city:"河南 焦作/济源"},		{code:"0392", city:"河南 鹤壁"},	{code:"0393", city:"河南 濮阳"},	{code:"0394", city:"河南 周口"},
  {code:"0395", city:"河南 漯河"},	{code:"0396", city:"河南 驻马店"},	{code:"0398", city:"河南 三门峡"},
  // 湖南
  {code:"0730", city:"湖南 岳阳"},	{code:"0731", city:"湖南 长沙"},	{code:"0732", city:"湖南 湘潭"},	{code:"0733", city:"湖南 株洲"},	{code:"0734", city:"湖南 衡阳"},
  {code:"0735", city:"湖南 郴州"},	{code:"0736", city:"湖南 常德"},	{code:"0737", city:"湖南 益阳"},	{code:"0738", city:"湖南 娄底"},	{code:"0739", city:"湖南 邵阳"},
  {code:"0743", city:"湖南 湘西"},	{code:"0744", city:"湖南 张家界"},	{code:"0745", city:"湖南 怀化"},	{code:"0746", city:"湖南 永州"},
  // 广东
  {code:"020", city:"广东 广州"},	{code:"0660", city:"广东 汕尾"},	{code:"0662", city:"广东 阳江"},	{code:"0663", city:"广东 揭阳"},	{code:"0668", city:"广东 茂名"},
  {code:"0750", city:"广东 江门"},	{code:"0751", city:"广东 韶关"},	{code:"0752", city:"广东 惠州"},	{code:"0753", city:"广东 梅州"},	{code:"0754", city:"广东 汕头"},
  {code:"0755", city:"广东 深圳"},	{code:"0756", city:"广东 珠海"},	{code:"0757", city:"广东 佛山"},	{code:"0758", city:"广东 肇庆"},	{code:"0759", city:"广东 湛江"},
  {code:"0760", city:"广东 中山"},	{code:"0762", city:"广东 河源"},	{code:"0763", city:"广东 清远"},	{code:"0766", city:"广东 云浮"},	{code:"0768", city:"广东 潮州"},
  {code:"0769", city:"广东 东莞"},
  // 广西
  {code:"0770", city:"广西 防城港"},	{code:"0771", city:"广西 南宁/崇左"},	{code:"0772", city:"广西 柳州/来宾"},
  {code:"0773", city:"广西 桂林"},	{code:"0774", city:"广西 梧州/贺州"}, {code:"0775", city:"广西 贵港/玉林"},
  {code:"0776", city:"广西 百色"},	{code:"0777", city:"广西 钦州"},	{code:"0778", city:"广西 河池"},	{code:"0779", city:"广西 北海"},
  // 四川
  {code:"028", city:"四川 成都"},	{code:"0812", city:"四川 攀枝花"},	{code:"0813", city:"四川 自贡"},	{code:"0816", city:"四川 绵阳"},	{code:"0817", city:"四川 南充"},
  {code:"0818", city:"四川 达州"},	{code:"0825", city:"四川 遂宁"},	{code:"0826", city:"四川 广安"},	{code:"0827", city:"四川 巴中"},	{code:"0830", city:"四川 泸州"},
  {code:"0831", city:"四川 宜宾"},	{code:"0832", city:"四川 内江/资阳"},	{code:"0833", city:"四川 乐山/眉山"},
  {code:"0834", city:"四川 凉山"},	{code:"0835", city:"四川 雅安"},	{code:"0836", city:"四川 甘孜"},	{code:"0838", city:"四川 德阳"},	{code:"0839", city:"四川 广元"},
  {code:"0873", city:"四川 阿坝"},
  // 贵州
  {code:"0851", city:"贵州 贵阳"},	{code:"0852", city:"贵州 遵义"},	{code:"0853", city:"贵州 安顺"},	{code:"0854", city:"贵州 黔南"},	{code:"0855", city:"贵州 黔东南"},
  {code:"0856", city:"贵州 铜仁"},	{code:"0857", city:"贵州 毕节"},	{code:"0858", city:"贵州 六盘水"},	{code:"0859", city:"贵州 黔西南"},
  // 云南
  {code:"0691", city:"云南 西双版纳"},	{code:"0692", city:"云南 德宏"},	{code:"0870", city:"云南 昭通"},	{code:"0871", city:"云南 昆明"},	{code:"0872", city:"云南 大理"},
  {code:"0873", city:"云南 红河"},	{code:"0874", city:"云南 曲靖"},	{code:"0875", city:"云南 保山"},	{code:"0876", city:"云南 文山"},	{code:"0877", city:"云南 玉溪"},
  {code:"0878", city:"云南 楚雄"},	{code:"0879", city:"云南 普洱"},	{code:"0883", city:"云南 临沧"},	{code:"0886", city:"云南 怒江傈"},	{code:"0887", city:"云南 迪庆"},
  {code:"0888", city:"云南 丽江"},
  // 西藏
  {code:"0891", city:"西藏 拉萨"},	{code:"0892", city:"西藏 日喀则"},	{code:"0893", city:"西藏 山南"},	{code:"0894", city:"西藏 林芝"},	{code:"0895", city:"西藏 昌都"},
  {code:"0896", city:"西藏 那曲"},	{code:"0897", city:"西藏 阿里"},
  // 陕西
  {code:"029", city:"陕西 西安"},	{code:"0910", city:"陕西 咸阳"},	{code:"0911", city:"陕西 延安"},	{code:"0912", city:"陕西 榆林"},	{code:"0913", city:"陕西 渭南"},
  {code:"0914", city:"陕西 商洛"},	{code:"0915", city:"陕西 安康"},	{code:"0916", city:"陕西 汉中"},	{code:"0917", city:"陕西 宝鸡"},	{code:"0919", city:"陕西 铜川"},
  // 甘肃
  {code:"0930", city:"甘肃 临夏"},	{code:"0931", city:"甘肃 兰州"},	{code:"0932", city:"甘肃 定西"},	{code:"0933", city:"甘肃 平凉"},	{code:"0934", city:"甘肃 庆阳"},
  {code:"0935", city:"甘肃 金昌/武威"},		{code:"0936", city:"甘肃 张掖"},	{code:"0937", city:"甘肃 嘉峪关/酒泉"},
  {code:"0938", city:"甘肃 天水"},	{code:"0939", city:"甘肃 陇南"},	{code:"0941", city:"甘肃 甘南"},	{code:"0943", city:"甘肃 白银"},
  // 青海
  {code:"0970", city:"青海 海北"},	{code:"0971", city:"青海 西宁"},	{code:"0972", city:"青海 海东"},	{code:"0973", city:"青海 黄南"},	{code:"0974", city:"青海 海南"},
  {code:"0975", city:"青海 果洛"},	{code:"0976", city:"青海 玉树"},	{code:"0977", city:"青海 海西"},
  // 宁夏
  {code:"0951", city:"宁夏 银川"},	{code:"0952", city:"宁夏 石嘴山"},	{code:"0953", city:"宁夏 吴忠"},	{code:"0954", city:"宁夏 固原"},	{code:"0955", city:"宁夏 中卫"},
  // 新疆
  {code:"0901", city:"新疆 塔城/图木舒克"},		{code:"0902", city:"新疆 哈密/新星"},	{code:"0903", city:"新疆 和田/昆玉"},
  {code:"0906", city:"新疆 阿勒泰/北屯"},	{code:"0908", city:"新疆 克孜勒苏柯尔"},	{code:"0909", city:"新疆 博尔塔拉/双河"},
  {code:"0990", city:"新疆 克拉玛依"},	{code:"0991", city:"新疆 乌鲁木齐"},	{code:"0992", city:"新疆 胡杨河"},	{code:"0993", city:"新疆 石河子/五家渠"},
  {code:"0994", city:"新疆 昌吉"},	{code:"0995", city:"新疆 吐鲁番"},	{code:"0996", city:"新疆 巴音郭楞/铁门关"},
  {code:"0997", city:"新疆 阿克苏/阿拉尔"},	{code:"0998", city:"新疆 喀什"},	{code:"0999", city:"新疆 伊犁哈萨克/可克达拉"},
];

export function formatPhone(phone: string) {
  if (phone) {
    if (phone[0] === "0" && [10, 11, 12].includes(phone.length)) {
      const area = PhoneAreaCodes.find(f => phone.startsWith(f.code));
      if (area) {
        if (area.code.length === 4) {
          // 当区号长度为 4 时
          if ([11, 12].includes(phone.length)) {
            // 4-3-4 或 4-4-4
            return area.code + " " + phone.slice(area.code.length, -4) + " " + phone.slice(-4);
          } else {
            return area.code + " " + phone.slice(area.code.length, area.code.length + 4) + " " + phone.slice(area.code.length + 4);
          }
        } else if (area.code.length === 3) {
          if (phone.length === 12) {
            // 3-3-3-3
            return area.code + " " + phone.slice(area.code.length, area.code.length + 4) + " " + phone.slice(area.code.length + 4);
          } else {
            // 当区号长度为 3 时
            // 3-4-4
            return area.code + " " + phone.slice(area.code.length, area.code.length + 4) + " " + phone.slice(area.code.length + 4);
          }
        }
      }
      // 首位为0 代表座机
    } else if (phone[0] === "1" && phone.length === 11) {
      // 首位为 1 代表手机
      return phone.slice(0, 3) + " " + phone.slice(3, 7) + " " + phone.slice(7);
    }
  }
  return phone;
}
